package Frame;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JDialog;
import javax.swing.JPanel;

import Function.FCBlockLibrary;
import Function.FCCorrect;

public class FCProgressBar extends JDialog {
	private double num = 0;
	private FCCorrect correct = new FCCorrect();
	private JPanel jp = new JPanel() {
		@Override
		protected void paintComponent(Graphics g) {
			g.setColor(Color.white);
			g.fillRect(0, 0, getWidth(), getHeight());
			g.setColor(Color.blue);
			g.fillRect(0, 0, (int) ((getWidth() - 5) * num), getHeight());
			g.setColor(Color.red);
			g.drawString((int) (num * 100) + "%", 10, 30);
		}
	};

	public FCProgressBar(String title, MapEditJpanel jpa, FCBlockLibrary blol) {
		newframe(title);
		correct.setMapData(jpa, blol, 0, this);
		new Thread(correct).start();
		setVisible(true);
	}

	private void newframe(String title) {
		setModal(true);
		setTitle(title);
		setBounds(0, 0, 300, 80);
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);

		jp.setBounds(0, 0, getWidth(), getHeight());
		this.add(jp);
	}

	public void setNum(double num) {
		this.num = num;
		jp.repaint();
		if (num >= 1) {
			new FCTip("地图检修", "检修完成!");
			this.dispose();
		}
	}
}
